package com.ticket.sass.common.entity.tenant;

import com.baomidou.mybatisplus.annotation.*;
import com.google.gson.Gson;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@TableName("shop_goods")
public class ShopGoodsEntity {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private String name;
    private BigDecimal discountPrice;
    private BigDecimal originalPrice;
    private String image;
    private Long cinemaId;
    private Long tenantId;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    @TableField(select = false)
    @TableLogic(value = "null", delval = "now()")
    private LocalDateTime deletedAt;

    @TableField(exist = false)
    private ShopGoodsStockEntity stock;

    @TableField(exist = false)
    private ShopGoodsDetailEntity detail;

    public List<String> imageList() {
        return new Gson().<ArrayList<String>>fromJson(image, ArrayList.class);
    }
    public String getMainCover() {
        var data = imageList();
        return data.isEmpty() ? "" : data.get(0);
    }
}
